package com.waves.task.dao;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.waves.task.domain.entity.Task;
import com.waves.task.domain.entity.TaskReceive;
import com.waves.task.domain.enums.TaskReceiveStatusEnum;
import com.waves.task.mapper.TaskReceiveMapper;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class TaskReceiveDao extends ServiceImpl<TaskReceiveMapper, TaskReceive> {

    public List<TaskReceive> getGtZero(long taskId) {
        return lambdaQuery().eq(TaskReceive::getTaskId, taskId)
                .gt(TaskReceive::getStatus, TaskReceiveStatusEnum.RECEIVE_STATUS_CANCEL.getType()).list();
    }

    public TaskReceive getByReceiverId(long taskId,long receiveId) {
        return lambdaQuery().eq(TaskReceive::getReceiverId, receiveId)
                .eq(TaskReceive::getTaskId,taskId)
                .ne(TaskReceive::getStatus,TaskReceiveStatusEnum.RECEIVE_STATUS_CANCEL)
                .one();
    }


    public Integer getCountByTaskId(long taskId) {
        return lambdaQuery().eq(TaskReceive::getTaskId,taskId).count();
    }

    public Integer saveAll(List<TaskReceive> list) {
        return baseMapper.saveAll(list);
    }
}
